package myListener;

import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;

import javax.swing.JLabel;

import myWindows.JMyVentana;

public class JTestComboBox extends JMyVentana{
    public JTestComboBox() {
        InitGUI();
    }
    
    private String nombres[] = {"bug1.jpg", "bug2.jpg", "bug3.jpg", "bug4.jpg"};
    private Icon iconos[] = {
        new ImageIcon(getClass().getResource(nombres[0])),
        new ImageIcon(getClass().getResource(nombres[1])),
        new ImageIcon(getClass().getResource(nombres[2])),
        new ImageIcon(getClass().getResource(nombres[3]))
    };
    private JComboBox lista;
    private JLabel etiqueta;
    
    public void InitGUI(){
        this.getContentPane().setLayout(new FlowLayout());
        this.setSize(350, 300);
        
        lista = new JComboBox(nombres);
        add(lista);
        lista.addItemListener(new ItemListener(){
                    public void itemStateChanged(ItemEvent e) {
                        if (e.getStateChange() == ItemEvent.SELECTED)
                            etiqueta.setIcon(iconos[lista.getSelectedIndex()]);
                    }
                });
        
        etiqueta = new JLabel(iconos[0]);
        add(etiqueta);
    }

    public static void main(String[] args) {
        JTestComboBox obj = new JTestComboBox();
        obj.setVisible(true);
    }
}
